import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
 * Created by JFormDesigner on Sun May 01 14:58:05 CDT 2011
 */



/**
 * @author Becca Emrick
 */
public class SaveCoasterWindow extends JFrame {
	public SaveCoasterWindow() {
		initComponents();
	}

	private void saveCoaster(ActionEvent e) {
		String coasterName = nameTextField.getText().trim();
		if(!coasterName.equals("")) {
			GameManager.GM.database.saveRollerCoaster(coasterName, GameManager.GM.glWindow.getCoaster());
		}
		GameManager.GM.saveWindow.setVisible(false);
	}

	private void cancelAction(ActionEvent e) {
		GameManager.GM.saveWindow.setVisible(false);
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		// Generated using JFormDesigner Evaluation license - Becca Emrick
		label1 = new JLabel();
		label2 = new JLabel();
		nameTextField = new JTextField();
		saveButotn = new JButton();
		cancelButton = new JButton();

		//======== this ========
		Container contentPane = getContentPane();
		contentPane.setLayout(null);

		//---- label1 ----
		label1.setText("Save As...");
		contentPane.add(label1);
		label1.setBounds(new Rectangle(new Point(20, 10), label1.getPreferredSize()));

		//---- label2 ----
		label2.setText("Coaster Name: ");
		contentPane.add(label2);
		label2.setBounds(new Rectangle(new Point(20, 40), label2.getPreferredSize()));
		contentPane.add(nameTextField);
		nameTextField.setBounds(135, 35, 170, nameTextField.getPreferredSize().height);

		//---- saveButotn ----
		saveButotn.setText("Save");
		saveButotn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				saveCoaster(e);
			}
		});
		contentPane.add(saveButotn);
		saveButotn.setBounds(new Rectangle(new Point(250, 80), saveButotn.getPreferredSize()));

		//---- cancelButton ----
		cancelButton.setText("Cancel");
		cancelButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				cancelAction(e);
			}
		});
		contentPane.add(cancelButton);
		cancelButton.setBounds(new Rectangle(new Point(160, 80), cancelButton.getPreferredSize()));

		{ // compute preferred size
			Dimension preferredSize = new Dimension();
			for(int i = 0; i < contentPane.getComponentCount(); i++) {
				Rectangle bounds = contentPane.getComponent(i).getBounds();
				preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
				preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
			}
			Insets insets = contentPane.getInsets();
			preferredSize.width += insets.right;
			preferredSize.height += insets.bottom;
			contentPane.setMinimumSize(preferredSize);
			contentPane.setPreferredSize(preferredSize);
		}
		pack();
		setLocationRelativeTo(getOwner());
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	// Generated using JFormDesigner Evaluation license - Becca Emrick
	private JLabel label1;
	private JLabel label2;
	private JTextField nameTextField;
	private JButton saveButotn;
	private JButton cancelButton;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
}
